// PropPageAbout.cpp : implementation file
//

#include "stdafx.h"
#include "NetTools.h"
#include "PropPageAbout.h"

CString GetIP()
{
	CString strIp;

	//Init winsock
	WSADATA wsaData;
	int nErrorCode = WSAStartup(MAKEWORD(1,1), &wsaData);
	if (nErrorCode != 0) {
		//Cannot initialize winsock
		return _T("");
	}

	char strHostName[81];
	if (gethostname(strHostName, 80)==0)
	{
		hostent *pHost = gethostbyname(strHostName);
		if (pHost->h_addrtype == AF_INET)
		{
			in_addr **ppip=(in_addr**)pHost->h_addr_list; 
			
			//Enumarate all addresses
			while (*ppip) 
			{
				in_addr ip=**ppip;
				strIp += CString(inet_ntoa(ip));
				ppip++; 
			}
		}
	}

	return strIp;
}

// CPropPageAbout dialog

IMPLEMENT_DYNAMIC(CPropPageAbout, CPropertyPage)

CPropPageAbout::CPropPageAbout()
	: CPropertyPage(CPropPageAbout::IDD)
{

}

CPropPageAbout::~CPropPageAbout()
{
}

void CPropPageAbout::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT_STATUS, m_oEditStatus);
}


BEGIN_MESSAGE_MAP(CPropPageAbout, CPropertyPage)
END_MESSAGE_MAP()


// CPropPageAbout message handlers

BOOL CPropPageAbout::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	CString sIPAddresses = GetIP();
	
	m_oEditStatus.SetWindowText(sIPAddresses);	

	return TRUE;
}